-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ts migration(src/pages): Migrated assigned files #6829
Ts migration(src/pages): Migrated assigned files #6829
Conversation
…component functions segregation
Gatsby Cloud Build Reportethereum-org-website-dev 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 27m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@M-Ivan thanks for the contribution!
Similar feedback as in your other PR. Lets use PageProps
+ the auto-generated query type.
- You can take a look at the
src/pages/index.tsx
file to take it as an example. - Also, take a look at this doc for more context https://github.com/ethereum/ethereum-org-website/blob/dev/docs/typescript.md
src/pages/404.tsx
Outdated
<StyledPage> | ||
<Content> | ||
<h1> | ||
<Translation id="we-couldnt-find-that-page" /> | ||
</h1> | ||
<p> | ||
<Translation id="try-using-search" />{" "} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need that extra space
src/pages/404.tsx
Outdated
@@ -10,14 +10,14 @@ const StyledPage = styled(Page)` | |||
margin-top: 4rem; | |||
` | |||
|
|||
const NotFoundPage = () => ( | |||
const NotFoundPage: React.FC = () => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a Page component, we are not defining it as a React.FC
. Lets keep the consistency across the other pages by only defining the props with PageProps
.
const NotFoundPage: React.FC = () => ( | |
const NotFoundPage = (props: PageProps) => { |
src/pages/assets.tsx
Outdated
data: Record<string, IGatsbyChildImageSharp> | ||
} | ||
|
||
const AssetsPage: React.FC<IProps> = ({ data }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the other PR, lets use PageProps
from gatsby and use the auto-generated types using Queries.{NameOfTheQuery}
.
src/pages/assets.tsx
Outdated
@@ -116,7 +143,7 @@ const AssetsPage = ({ data }) => { | |||
<AssetDownload | |||
title={translateMessageId("page-assets-hero", intl)} | |||
alt={translateMessageId("page-assets-hero", intl)} | |||
image={data.hero} | |||
image={getImage(data.hero)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to do getImage
here since AssetDownload
is already doing that for us.
src/pages/bug-bounty.tsx
Outdated
link: string | ||
} | ||
|
||
const BugBountiesPage: React.FC<IProps> = ({ data, location }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other pages, lest use PageProps
.
src/pages/bug-bounty.tsx
Outdated
@@ -326,7 +361,7 @@ const BugBountiesPage = ({ data, location }) => { | |||
? getImage(data.lighthouseDark) | |||
: getImage(data.lighthouseLight) | |||
|
|||
const specs = [ | |||
const specs: ISpec[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency,
const specs: ISpec[] = [ | |
const specs: Array<ISpec> = [ |
src/pages/community.tsx
Outdated
description: string | ||
} | ||
|
||
const CommunityPage: React.FC<IProps> = ({ data }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, PageProps
src/pages/community.tsx
Outdated
@@ -316,7 +335,7 @@ const CommunityPage = ({ data }) => { | |||
alt: translateMessageId("page-community-hero-alt", intl), | |||
} | |||
|
|||
const cards = [ | |||
const cards: ICard[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const cards: ICard[] = [ | |
const cards: Array<ICard> = [ |
…hod issue with typescript
…gatsby call, also fixed type of image in AssetDownload.tsx to be Record<string, unknown>
…moved unnecessary export statements
src/components/AssetDownload.tsx
Outdated
@@ -26,7 +26,7 @@ interface IPropsWithSVG extends IPropsBase { | |||
} | |||
interface IPropsWithImage extends IPropsBase { | |||
svg?: never | |||
image: string | |||
image: Record<string, unknown> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pettinarip since this prop is supposed to receive the GatsbyImageData object i changed this type to match any object. It was set to string before and it was a pain to make it work when passing a Gatsby auto-generated type (from the Queries namespace).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice! as commented in the other comment, we will leave it as any
for now. Once we have better types from gatsby we will refactor and fix all the images types 👍🏼
src/pages/assets.tsx
Outdated
@@ -117,7 +118,7 @@ const AssetsPage = ({ data }) => { | |||
<AssetDownload | |||
title={translateMessageId("page-assets-hero", intl)} | |||
alt={translateMessageId("page-assets-hero", intl)} | |||
image={data.hero} | |||
image={data.hero as Record<string, unknown>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pettinarip Type assetion here is for the AssetDownload component prop to don't cry. It actually complains a lot because the props of the component expect a non-nullable object, even tho in the component this specific prop value is used for a gatsby call is using getSrc, a null-safe method (docs here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but there are some issues with the getImage
types. In the overrides.d.ts
we are overriding the types for this function to basically accepts any
as its argument. So, in order to keep it simple, we can just accept any
in AssetDownload
while we wait for a proper fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@M-Ivan thanks for the PR! this looks great! I'm pushing some minor changes and reverting the md changes.
src/pages/bug-bounty.tsx
Outdated
} | ||
|
||
interface ISpec { | ||
title: JSX.Element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: JSX.Element | |
title: ReactNode |
src/pages/assets.tsx
Outdated
@@ -117,7 +118,7 @@ const AssetsPage = ({ data }) => { | |||
<AssetDownload | |||
title={translateMessageId("page-assets-hero", intl)} | |||
alt={translateMessageId("page-assets-hero", intl)} | |||
image={data.hero} | |||
image={data.hero as Record<string, unknown>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but there are some issues with the getImage
types. In the overrides.d.ts
we are overriding the types for this function to basically accepts any
as its argument. So, in order to keep it simple, we can just accept any
in AssetDownload
while we wait for a proper fix.
Description
Migrated:
Related Issue
PR Is related with 6392